<?php

namespace App\Models\Acl;

use Laracasts\Presenter\PresentableTrait;
use Spatie\Permission\Models\Permission as SpatiePermission;

class Permission extends SpatiePermission
{
	use PresentableTrait; 

    protected $table = 'acl_permissions';

    protected $guard_name = 'admin';

    protected $presenter = 'App\Http\Presenters\Acl\PermissionPresenter';

    public function children()
    {
        return $this->hasMany('App\Models\Acl\Permission', 'parent', 'id');
    }

    public function parent()
    {
    	if( $this->parent == 0)
    		return $this;

    	return $this->find($this->parent);
    }


    public function scopeParents($query)
    {
        return $query->where('parent', 0);
    }
}
